<template>
    <div class="row">
        <el-checkbox v-model="comp.enabled">{{ comp.__classname__ }}</el-checkbox>
        <el-button round size="small" :icon="Document" @click="gm.toConsole(comp)"></el-button>
    </div>

    <div class="row-start">
        <el-text class="span-title" truncated>CustomMaterial</el-text>
        <el-input size="small" disabled :value="gm.targetName(comp.customMaterial)" />
    </div>

    <div class="row-start">
        <el-text class="span-title" truncated>Color</el-text>
        <el-color-picker size="small" color-format="hex" show-alpha v-model="Model.color" />
        <el-input size="small" v-model="Model.color" />
    </div>

    <div class="row-start">
        <el-text class="span-title" truncated>SpriteAtlas</el-text>
        <el-input size="small" disabled :value="gm.targetName(comp.spriteAtlas)" />
    </div>

    <div class="row-start">
        <el-text class="span-title" truncated>SpriteFrame</el-text>
        <el-input size="small" disabled :value="gm.targetName(comp.spriteFrame)" />
    </div>

    <div class="row-start">
        <el-text class="span-title" truncated>Grayscale</el-text>
        <el-checkbox v-model="comp.grayscale" />
    </div>

    <div class="row-start">
        <el-text class="span-title" truncated>SizeMode</el-text>
        <el-select v-model="comp.sizeMode" size="small">
            <el-option v-for="item in sizeMode.__enums__" :key="item.value" :label="item.name" :value="item.value" />
        </el-select>
    </div>

    <div class="row-start">
        <el-text class="span-title" truncated>Type</el-text>
        <el-select v-model="comp.type" size="small">
            <el-option v-for="item in type.__enums__" :key="item.value" :label="item.name" :value="item.value" />
        </el-select>
    </div>

    <div class="row-start" v-if="comp.type == type.SIMPLE">
        <el-text class="span-title" truncated>Trim</el-text>
        <el-checkbox v-model="comp.trim" />
    </div>

    <div v-if="comp.type == type.FILLED">
        <div class="row-start">
            <el-text class="span-title" truncated>FillType</el-text>
            <el-select v-model="comp.fillType" size="small">
                <el-option v-for="item in fillType.__enums__" :key="item.value" :label="item.name" :value="item.value" />
            </el-select>
        </div>

        <div class="row-start">
            <el-text class="span-title" truncated>FillCenter</el-text>
            <el-input-number size="small" :controls="false" :step="0.1" v-model="Model.fillCenterX">
                <template #suffix>
                    <span>X</span>
                </template>
            </el-input-number>
            <el-input-number size="small" :controls="false" :step="0.1" v-model="Model.fillCenterY">
                <template #suffix>
                    <span>Y</span>
                </template>
            </el-input-number>
        </div>

        <div class="row-start">
            <el-text class="span-title" truncated>FillStart</el-text>
            <el-input-number size="small" :controls="false" :step="0.1" :min=0 :max=1 v-model="comp.fillStart" />
        </div>

        <div class="row-start">
            <el-text class="span-title" truncated>FillRange</el-text>
            <el-input-number size="small" :controls="false" :step="0.1" :min=-1 :max=1 v-model="comp.fillRange" />
        </div>
    </div>

</template>

<script lang="ts" setup>
import { Document } from '@element-plus/icons-vue'
import gm from './gm'

const props = defineProps<{
    comp: CCComponent,
    update: Number,
}>()

const sizeMode = cc.Sprite.SizeMode
const type = cc.Sprite.Type
const fillType = cc.Sprite.FillType

class Model {
    static get comp() {
        return props.comp
    }

    static get color() {
        return gm.toHexColor(this.comp.color)
    }

    static set color(value: string) {
        this.comp.color = gm.toCCColor(value)
    }

    static get fillCenterX() {
        return this.comp.fillCenter.x
    }

    static set fillCenterX(value: number) {
        const ori = this.comp.fillCenter
        ori.x = value
        this.comp.fillCenter = ori
    }

    static get fillCenterY() {
        return this.comp.fillCenter.y
    }

    static set fillCenterY(value: number) {
        const ori = this.comp.fillCenter
        ori.y = value
        this.comp.fillCenter = ori
    }
}
</script>